<template>
	<div id="news_detail" class="table" v-if="formVisible">
		<div class="container">
			<div style="text-align:center;">
				<div style="text-align:left;margin:0 auto;">
					<el-form :model="modelData" label-width="120px" class="demo-ruleForm">
						<div class="rows">
							<el-form-item label="封面">
								<el-upload class="avatar-uploader" width="100" :limit='1' name="file" :action="globaldata.uploadUrl" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
									<img v-if="modelData.logo" :src="globaldata.imgBaseUrl+modelData.logo" class="avatar">
									<i v-else class="el-icon-plus avatar-uploader-icon"></i>
								</el-upload>
							</el-form-item>
						</div>
						<div class="rows">
							<el-form-item class="text_align" label="标题：">
								<el-input v-model="modelData.title" :maxlength="30"></el-input>
							</el-form-item>
							<el-form-item label="公司全称:">
								<el-input v-model="modelData.projectIntro" :maxlength="200" placeholder="请输入公司全称">
								</el-input>
							</el-form-item>
							<!--<el-form-item label="融资机构：">
								<el-select v-model="modelData.companyId" placeholder="请选择">
									<el-option v-for="item in companys" :key="item.id" :label="item.companyName" :value="item.id"></el-option>
								</el-select>
							</el-form-item>-->
						</div>
						<div class="rows">
							<el-form-item label="城市：">
								<el-select v-model="modelData.city" placeholder="请选择">
									<el-option v-for="(value,key) in citys" :key="key" :label="value" :value="key"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="项目阶段：">
								<el-select v-model="modelData.stage" placeholder="请选择">
									<el-option v-for="(value,key) in stages" :key="key" :label="value" :value="key"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="融资轮次：">
								<el-select v-model="modelData.investTag" placeholder="请选择">
									<el-option v-for="(value,key) in investTags" :key="key" :label="value" :value="key"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<el-form-item label="历史融资伦次:" v-if="modelData.id > 0">
							<el-input type="input" v-model="modelData.projectInvestTags" :maxlength="200" :disabled="true">
							</el-input>
						</el-form-item>						
						<el-form-item label="项目介绍:">
							<el-input type="textarea" v-model="modelData.projectContent" :maxlength="200" placeholder="请输入项目介绍">
							</el-input>
						</el-form-item>
						<div class="rows">
							<el-form-item class="text_align" label="公司网站：">
								<el-input v-model="modelData.companyUrl" :maxlength="100"></el-input>
							</el-form-item>
							<el-form-item class="text_align" label="招行推荐：">
								<el-switch v-model="modelData.hotProject" active-color="#13ce66" inactive-color="#999">
								</el-switch>
							</el-form-item>
							<el-form-item class="text_align" label="招行认证：">
								<el-switch v-model="modelData.isCmbCertified" active-color="#13ce66" inactive-color="#999" :active-value=1 :inactive-value=0>
								</el-switch>
							</el-form-item>
						</div>
						<el-form-item class="role_area" label="所属行业：">
							<el-checkbox-group v-model="selectedjobs" size="mini">
								<el-checkbox v-for="(value,key) in careerjobs" :key="key" :label="key">{{value}}</el-checkbox>
							</el-checkbox-group>
						</el-form-item>
						<el-form-item class="role_area" label="标签：">
							<el-checkbox-group v-model="selectedtags" size="mini">
								<el-checkbox v-for="(value,key) in projecttags" :key="key" :label="key">{{value}}</el-checkbox>
							</el-checkbox-group>
						</el-form-item>
						<div class="rows">
							<el-form-item class="role_area" label="BP计划书：">
								<el-upload class="upload-demo" :action="globaldata.uploadUrl" :before-upload="beforeAvatarUpload1" :limit="1" :file-list="fileList" :on-success="handleAvatarSuccess1" :on-remove="handleRemove">
									<el-button size="small" type="primary">点击上传</el-button>
									<div slot="tip" class="el-upload__tip">只能上传pdf格式的文件，且不超过4MB</div>
								</el-upload>
							</el-form-item>
							<el-form-item class="text_align" label="项目金额：">
								<!--<el-input-number v-model="modelData.projectPrice" :precision="4" :min="0"></el-input-number>-->
								<el-input v-model="modelData.projectPrice" :maxlength="100"></el-input>
							</el-form-item>
						</div>
					</el-form>
				</div>
			</div>
			<div style="clear:both;"></div>
			<div slot="footer" class="dialog-footer my_flex_right">
				<el-button @click="close()">返回</el-button>
				<el-button type="primary" @click="save()">保存</el-button>
			</div>
		</div>
	</div>
</template>

<script>
	import service from '@/js/services/projectservice.js';
	import companyservice from '../../../js/services/companyservice.js';
	export default {
		props: {
			id: 0,
			parentDetailData: {}
		},
		data() {
			return {
				modelData: {},
				companys: [],
				careerjobs: [],
				selectedjobs: [],
				formVisible: false,
				projecttags: [],
				selectedtags: [],
				projectInvestList:[],
				imageUrl: '',
				citys: [],
				stages:[],
				searchcondition: {
					pageNum: 1,
					pageSize: 100000
				},
				investTags: [],
				fileList: []
			}
		},
		watch: {
			formVisible(newVal, oldVal) {
				if(newVal) { //详情页弹出
					this.resetData();
					let self = this;
					let param_arr = ['career_tag']; //所属行业
					this.tool.getDirByKey(this, param_arr).then(() => {
						self.careerjobs = self.$store.state.career_tag;
					});
					param_arr = ['city']; //城市
					this.tool.getDirByKey(this, param_arr).then(() => {
						self.citys = self.$store.state.city;
					});
					param_arr = ['invest']; //融资轮次
					this.tool.getDirByKey(this, param_arr).then(() => {
						self.investTags = self.$store.state.invest;
					});
					param_arr = ['project_tag']; //融资轮次
					this.tool.getDirByKey(this, param_arr).then(() => {
						self.projecttags = self.$store.state.project_tag;
					});
					param_arr = ['stage']; //融资轮次
					this.tool.getDirByKey(this, param_arr).then(() => {
						self.stages = self.$store.state.stage;
					});
					companyservice.getAllCompanys(this, function(res) {
						self.companys = res.data; //机构
					});
					service.getModelData(this);
				}
			},
		},
		created() {

		},
		mounted() {},
		methods: {
			resetData() {
				this.modelData = {
					id: null,
					logo: null,
					title: null,
					projectIntro: null,
					tags: null,
					projectPrice: null,
					companyId: null,
					projectContent: null,
					investTag: null,
					city: null,
					stage:null,
					careerTags: null,
					companyUrl: null,
					bpAttactId: null,
					hotProject: null,
					isCmbCertified:null,
					projectInvestTags:null
				};
				this.selectedjobs = [];
				this.selectedtags = [];
				this.fileList = [];
			},
			show() {
				this.formVisible = true;
			},
			save() {
//				let temp = this.modelData.isCmbCertified;
//				this.modelData.isCmbCertified=temp=="true"?1:0;
				service.handleSave(this);
			},
			close() {
				this.parentDetailData.isTabelShow = true;
				this.formVisible = false;
			},
			handleAvatarSuccess(res, file) {
				if(res.code == 1) {
					this.modelData.logo = res.data.id;
				} else {
					this.$message({
						message: res.msg,
						type: 'error'
					});
				}
			},
			handleRemove(file, fileList) {
				this.modelData.bpAttactId = null;
				this.modelData.bpAttactName = null;
				this.fileList = [];
			},
			handleAvatarSuccess1(files, fileList) {
				this.modelData.bpAttactId = files.data.id;
				this.modelData.bpAttactName = files.data.fileOriginName;
				this.fileList = [];
				this.fileList.push({
					name: files.data.fileOriginName
				});
			},
			beforeAvatarUpload(file) {
				return this.validatetool.validateImgSizeAndType(this, file);
			},
			beforeAvatarUpload1(file) {
				return this.validatetool.validateImgSizeAndType(this, file, '.pdf', 4);
			}
		},

	}
</script>
<style lang="less">

</style>